<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$mid=intval($_RQ['mid'])?:$_SESSION['uid'];
	if($mid){
		$this->session('mid',$mid);
	}
	$user=pdo_get('jy_xiaoeknow_user',array('mid'=>$mid,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']));
	$member=pdo_get('core_members',array('id'=>$mid,'uniacid'=>$_SESSION['uniacid']),array('id','credit1','credit2','mobile','groupid','avatar','nickname'));
	$user['nickname']=$user['nickname']?:$member['nickname'];
	set_html('title',$user['nickname'].'的课程');
	$return['params']=array('type'=>$type?:'wechat','keyword'=>'');
	if($_RQ['keyword']){
		$return['params']['keyword']=$_RQ['keyword'];
	}
	$return['member']=$member;
	$return['user']=$user;
	$data['fansnums']=pdo_count('jy_xiaoeknow_userlog',array('uniacid'=>$_SESSION['uniacid'],'isfollow'=>1,'merchid'=>$_SESSION['onemerchid'],'mid'=>$mid));
	$data['videonums']=pdo_count('jy_xiaoeknow_video',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'mid'=>$mid));
	$data['readnum']=pdo_getsum('jy_xiaoeknow_video',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'mid'=>$mid),'readnum');
	$return['data']=$data;
	exi($return);
}
if($_RQ['op']=='getlist'){
	$return['params']=array();
	$mid=$this->session('mid');
	$params=array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'mid'=>$mid);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);	
	}
	if($_RQ['keyword']){
		$params['title like']='%'.$_RQ['keyword'].'%';
		$return['params']['keyword']=$_RQ['keyword'];		
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_xiaoeknow_video',$params,array($pindex,$psize),$total,$fields,'','updatetime desc');
	foreach($list as &$kv){
			$kv['thumb']=tomedia($kv['thumb']);
	}	
	//按点赞数排序作品
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$item['updatetime']=$item['updatetime']?:$item['createtime'];
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['thumb']=tomedia($item['thumb']);
			$lasttime=TIMESTAMP-$item['updatetime'];
			if($lasttime>24*3600){
				$item['updatetimetitle']=intval($lasttime/24*3600).'天前';
			}elseif($lasttime>=3600){
				$item['updatetimetitle']=intval($lasttime/3600).'小时前';
			}else{
				$item['updatetimetitle']=intval($lasttime/60).'分钟前';
			}
			$item['likenum']=pdo_count('jy_xiaoeknow_video_log',array('video_id'=>$item['id'],'uniacid'=>$_SESSION['uniacid'],'islike'=>1),'id');
			$quan_log=pdo_get('jy_xiaoeknow_video_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'video_id'=>$item['id']));
			if($quan_log['id']){
				if($quan_log['isadd']==1){
					$item['islook']=2;
				}else{
					$item['islook']=1;
				}
			}
			
		}
	}
	$return['list']=$list;
	$return['params']['page'] =$pindex;
	exi($return);
}
if($_RQ['op']=='del'){
	if(!$_RQ['id']){
		exi('课程不存在哦！','error');
	}
	pdo_delete('jy_xiaoeknow_video',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除成功！');

}